package com.example.student.config;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.autoconfigure.ConfigurationCustomizer;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.annotation.EnableTransactionManagement;

/**
 * mybatis-plus 插件的配置文件
 */
@EnableTransactionManagement
@MapperScan("com.example.student.generated.mapper")
@Configuration
public class

MybatisPlusConfig {

/*  PaginationInterceptor 已过时
    @Bean
    public PaginationInterceptor paginationInterceptor()
    {
        return new PaginationInterceptor();
    }
*/
    /*新增拦截器 解决多租户和分页，插件一级和二级缓存不正确问题*/
    /*看不懂，更新一下版本号拦截器解决缓存的那个方法没了，艹*/
    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor()
    {
        MybatisPlusInterceptor interceptor=new MybatisPlusInterceptor();
        //在这里 DbType 写上自己的数据库类型，数据库类型错误，拦截器也不生效
        interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
        return interceptor;
    }
}
